from extractors.base_extractor import BaseExtractor

class DemoExtractor(BaseExtractor):
    def __init__(self, info_dict,one_line_mode_return_result=True):
        super(DemoExtractor,self).__init__(info_dict,one_line_mode_return_result=one_line_mode_return_result)




    def checkIfNeedParse(self):
        '''
        判断是不是需要走解析
        return True就是需要
        return false就是不需要
        '''
        return True

    def common_replace_word(self,text):
        '''
        对网页进行一些词条替换
        '''
        return text

    def parse_announcement_info(self):
        '''
        各自去根据各种网页情况，写分支处理。。
        如果返回为None或者{}，则会去调用commom_announcement_parse走通用解析
        '''
        return {}

    def get_infos_from_otherway(self,result,html=None):
        '''
        对提取结果进行一些变换；比如没有项目名称，需要从标段名称里面提取
        或者从标题里面获取项目名称
        '''
        return result

    def clean_dict_keys(self,result):
        '''
        对result里面的一些字段进行简单的处理，比如清洗掉无用字符等
        '''
        return result


#
if __name__ == '__main__':
    import requests
    from pprint import pprint
    zhaobiao_url = "http://www.jszb.com.cn/jszb/YW_info/ZhaoBiaoGG/ViewReportDetail.aspx?RowID=692652&categoryNum=012&siteid=1"
    zhongbiao_url = "http://www.jszb.com.cn/JSZB/yw_info/ZhongBiaoGS/ViewGSDetail.aspx?RowID=1297866&siteid=1&categoryNum=7"
    not_in_url = "http://www.jszb.com.cn/JSZB/yw_info/ZiGeYS/ViewYSDetail.aspx?RowID=158068&siteid=1&categoryNum=8"
    bid_evaulate_url = "http://www.jszb.com.cn/JSZB/yw_info/HouXuanRenGS/ViewHXRDetail.aspx?GongGaoGuid=ec62fb01-6c99-4863-aecc-6eb081380a30"

    req = requests.get(zhaobiao_url)#通过修改网址，得到不同的结果
    info_dict = {}
    info_dict['html'] = req.text
    info_dict['公告类型'] = "招标公告"
    info_dict['province'] = "招标公告"
    info_dict['source_type'] = "招标公告"
    info_dict['origin_url'] = "招标公告"
    obj = DemoExtractor(info_dict)#把信息传给类
    result = obj.output_extractor_dict(use_new=True)#解析
    pprint(result)